/*******************************************************************************
 * Copyright (C) 2013 Jeremy Brodt and Kevin Gillespie
 * Description: Motor Controller Driver
 *         $Id: motor.c 49 2014-05-01 21:06:14Z brodtj1212@gmail.com $
 *******************************************************************************
 */

#include <stdint.h>
#include "config.h"
#include "errors.h"
#include "tmr.h"

#include "car.h"
#include "motor.h"

/****************************************************************************/
int motor_init(void)
{
  int err;
  tmr_cfg_pwm_t config;

  if ((err = tmr_init(TMR_MOTOR_L, MXC_S_TMR_CN_PRES_PDIV_BY_2048)) != E_NO_ERROR) {
    return err;
  }

  config.pol = 1;
  config.per_cnt = 264;  // 100 Hz
  config.duty_cnt = 0;

  if ((err = tmr_cfg_pwm(TMR_MOTOR_L, &config)) != E_NO_ERROR) {
    return err;
  }

  if ((err = tmr_cfg_pwm(TMR_MOTOR_R, &config)) != E_NO_ERROR) {
    return err;
  }

  tmr_enable(TMR_MOTOR_L);
  tmr_enable(TMR_MOTOR_R);

  return E_NO_ERROR;
}

/****************************************************************************/
void motor_set(unsigned int wheel, unsigned int dir, uint8_t value)
{
}

/****************************************************************************/
void motor_stop(unsigned int wheel)
{
}

/****************************************************************************/
void motor_coast(unsigned int wheel)
{
}

